home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Documentation
/
Books
/
Learn Java on the Macintosh
/
Learn Java Projects
/
11.06 - payroll
/
Payroll.java
< prev
next >
Wrap
Text File
|
1996-04-22
|
2KB
|
89 lines
/* -----------------------------------------------------------
This illustrates the beginning of an applet to keep track
of employees in a database. This version defines an
Employee class but only adds the text fields to the applet
for use once more of the applet is developed.
Java's classes: Applet (applet)
TextField (awt) for entering new employee data
Label (awt) read-only text
GridLayout (awt) aligns by columns and rows
Custom classes: Payroll
Employee payroll information
----------------------------------------------------------- */
import java.applet.Applet;
import java.awt.*;
public class Payroll extends Applet {
TextField textFieldEmployee;
TextField textFieldWage;
TextField textFieldHours;
Label labelEarned;
/* Create user interface needed by this applet. */
public void init() {
// Arrange the user interface in a grid.
setLayout(new GridLayout(4,2)); // 4 rows, 2 columns
// 1st row
add(new Label("Employee number:"));
textFieldEmployee = new TextField(20); // 20 columns wide
add(textFieldEmployee);
// 2nd row
add(new Label("Hourly wage:"));
textFieldWage = new TextField(20); // 20 columns wide
add(textFieldWage);
// 3rd row
add(new Label("Hours worked:"));
textFieldHours = new TextField(20); // 20 columns wide
add(textFieldHours);
// 4th row
add(new Label("Earned income:"));
labelEarned = new Label();
add(labelEarned);
}
/** Detect keyboard entry. */
public boolean action(Event e, Object arg) {
if (e.target == textFieldEmployee) {
System.out.println("Employee number");
} else if (e.target == textFieldWage) {
System.out.println("Hourly wage");
} else if (e.target == textFieldHours) {
System.out.println("Hours worked");
}
return super.action(e, arg);
}
}
/** Maintain payroll information for an employee. */
class Employee {
int idNumber;
int hourlyWage;
int hoursWorked;
int earnedIncome() {
return hourlyWage * hoursWorked;
}
}